home *** CD-ROM | disk | FTP | other *** search
- /*
- CDPause - An XFCN to pause CDROM audio play
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/11/08 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C -q2 CDPause.c
- link -sn Main=CDPause -sn STDIO=CDPause ∂
- -sn INTENV=CDPause -rt XFCN=42 ∂
- -m CDPAUSE CDPause.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
-
- /* prototype definitions for functions */
- OSErr APause(short, short);
- int AreWePlaying(short);
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDPause
- *
- * Purpose: pause audio play
- *
- * Returns: result of driver call to pause
- * normally 0, but could have parameter error or
- * other error if non-existent block is specified
- *
- * Side Effects:
- *
- * Description: We need one parameter (or none):
- * 1) pauseMode. This could be either 0 to pause, or
- * 1 to stop pause and resume play.
- * If we don't get this parameter, toggle from the current
- * status.
- * Get the famous global ioRefNum (from previously
- * calling CDOpen())
- *
- ************************************************************************/
- pascal void
- CDPause(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- Str31 returnString;
- OSErr result;
- short ioRefNum;
- Handle refHandle;
- short pauseMode;
-
- /* Must be one parameter */
- if ((paramPtr->paramCount) > 1)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- ioRefNum &= 0xFFFF; /* remove vRefNum; not needed. */
-
- if (paramPtr->paramCount == 1)
- pauseMode = atoi(*(paramPtr->params[0]));
- else
- pauseMode = AreWePlaying(ioRefNum);
-
- /* Since the user always thinks 0 means pause, and the driver thinks
- ** 1 is pause for this call, we must switch the meaning of these
- ** two values.
- */
- if (pauseMode == 0)
- pauseMode = 1;
- else if (pauseMode == 1)
- pauseMode = 0;
- else
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- result = APause(ioRefNum, pauseMode);
-
- /* Convert result to string & return it as error */
- NumToStr(paramPtr, (long) result, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
-
- /************************************************************************
- *
- * Function: APause
- *
- * Purpose: pause/resume CD play
- *
- * Returns: OSErr. Probably either
- * noErr everything's hunky-dory!
- * paramErr you messed up the call somehow.
- *
- * Side Effects: pauses audio play or resumes it.
- *
- * Description: Simply call the driver.
- *
- ************************************************************************/
- OSErr
- APause(refNum, mode)
- short refNum;
- short mode;
- {
- CDPauseParam myPB;
- OSErr result;
-
- myPB.ioCompletion = 0;
- myPB.ioNamePtr = (char *) 0;
- myPB.ioVRefNum = 1;
- myPB.ioCRefNum = refNum;
- myPB.csCode = APAUSE;
- myPB.pauseMode = mode;
-
- result = PBControl(&myPB, false);
- return result;
- }
-
-
- /************************************************************************
- *
- * Function: AreWePlaying
- *
- * Purpose: return CD audio status
- *
- * Returns: a value to indicate whether we are playing or not.
- * 1 = we're paused
- * 0 = we're playing, or finished, or whatever.
- * Notice that these values are meant to be the same as
- * what a user would type to CDPause to get it to play
- * or pause.
- *
- * Side Effects: none.
- *
- * Description: Simply call the driver and return the audio status
- * byte that the driver gives us.
- *
- ************************************************************************/
- int
- AreWePlaying(refNum)
- short refNum;
- {
- CDStatusParam myPB;
- short result;
-
- myPB.ioCompletion = 0;
- myPB.ioNamePtr = (char *) 0;
- myPB.ioVRefNum = 1;
- myPB.ioCRefNum = refNum;
- myPB.csCode = ASTATUS;
-
- PBControl(&myPB, false);
-
- if (myPB.audioStatus == 1) /* we're currently paused */
- result = 1; /* play */
- else
- result = 0; /* pause */
- return result;
- }
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-